package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Attachment;
import com.ruoyi.system.domain.SysTopic;
import com.ruoyi.system.domain.TopicType;
import com.ruoyi.system.service.TopicTypeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.listener.Topic;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目类型表(TopicType)表控制层
 *
 * @author makejava
 * @since 2024-07-28 10:24:57
 */
@RestController
@RequestMapping("topicType")
public class TopicTypeController extends BaseController {

    /**
     * 服务对象
     */
    @Resource
    private TopicTypeService topicTypeService;

    /**
     * 根据课程id查出题目类型和对应的附件
     * @param courseId
     * @return
     */
    @GetMapping("/course/{id}")
    public AjaxResult queryAllByCourseId(@PathVariable("id") String courseId) {
        return success(topicTypeService.queryAllByCourseId(courseId));
    }

    /**
     * 分页查询
     *
     * @param topicType   筛选条件
     * @return 查询结果
     */
    @GetMapping
    public TableDataInfo queryByPage(TopicType topicType) {
        return getDataTable(this.topicTypeService.queryByPage(topicType));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return success(this.topicTypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param topicType 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(TopicType topicType) {
        return success(this.topicTypeService.insert(topicType));
    }

    /**
     * 编辑数据
     *
     * @param topicType 实体
     * @return 编辑结果
     */
    @PutMapping
    public AjaxResult edit(TopicType topicType) {
        return success(this.topicTypeService.update(topicType));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public AjaxResult deleteById(Long id) {
        return success(this.topicTypeService.deleteById(id));
    }

}

